package com.jyw.business.obstacles.domain.dto.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.obstacles.constant.OrderCurrStateConstant;
import com.jyw.business.obstacles.constant.OrderDealTypeConstant;
import com.jyw.business.obstacles.domain.ObsOrderFault;
import com.jyw.business.obstacles.domain.ObsOrderInfo;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.FileUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.Date;
import java.util.List;

/**
 * @author 沈峻
 * @ClassName OrderEditDto
 * @Description 工单修改请求实体
 * @Date 2023/8/21 10:36
 **/
@ApiModel("工单修改请求实体")
@Data
public class OrderEditDto {

    @ApiModelProperty("工单号")
    @NotEmpty(message = "工单号不能为空")
    private String orderNum;

    /** 创建时间 */
    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date createTime;

    @ApiModelProperty("工单来源")
    private Integer source;

    /** 实际报修地址 */
    @ApiModelProperty("实际报修地址")
    private Long actualRepairPlace;

    /** 故障分类 */
    @ApiModelProperty("故障分类")
    private String faultType;

    @ApiModelProperty("故障描述")
    private String faultRemark;

    @ApiModelProperty("预计工时")
    private Integer reqTime;

    @ApiModelProperty("期望完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date completeTime;

    @ApiModelProperty("紧急程度")
    private Integer degree;

    @ApiModelProperty("影响范围")
    private Integer rangeType;

    @ApiModelProperty("响应类型")
    private Integer responseType;

    @ApiModelProperty("预约时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date appointment;

    @ApiModelProperty("资产名称")
    private String equipment;

    /** 故障设备位置 */
    @ApiModelProperty("资产位置")
    private String equipmentAddress;

    /** 故障设备位置id */
    @ApiModelProperty("资产位置id")
    private Long equipmentAddressId;

    @ApiModelProperty("附件")
    private List<SimpleFileVo> enclosure;

    @ApiModelProperty("报修电话")
    private String phone;

    @ApiModelProperty("报修人")
    private String user;

    @ApiModelProperty("报修科室")
    private Long deptId;

    /** 报修地址 */
    @ApiModelProperty("报修地址")
    private String place;


    public ObsOrderInfo buildOrder(ObsOrderInfo orderInfo){
        orderInfo.setDeptId(getDeptId());
        orderInfo.setPlace(getPlace());
        orderInfo.setPhone(getPhone());
        orderInfo.setUser(getUser());
        orderInfo.setReception(SecurityUtils.getUserId());
        return orderInfo;
    }


    public ObsOrderFault buildOrderFault(ObsOrderFault orderFault) {
        ObsOrderFault newFault = new ObsOrderFault();
        BeanUtils.copyProperties(orderFault,newFault);
        newFault.setSource(getSource());
        newFault.setFaultType(getFaultType());
        newFault.setFaultRemark(getFaultRemark());
        newFault.setDegree(getDegree());
        newFault.setRangeType(getRangeType());
        newFault.setResponseType(getResponseType());
        newFault.setAppointment(getAppointment());
        newFault.setEnclosureId(FileUtils.fileToId(getEnclosure()));
        newFault.setCompleteTime(getCompleteTime());
        newFault.setActualRepairPlace(getActualRepairPlace());
        newFault.setEquipment(getEquipment());
        newFault.setEquipmentAddress(getEquipmentAddress());
        newFault.setEquipmentAddressId(getEquipmentAddressId());
        newFault.setReqTime(getReqTime());
        return newFault;
    }
}
